<template>
	<view class="content">
		<view class="top">
			<view class="top_bg">
				<image src="@/pages/groupbuy/static/home/tit_bg.png" ></image>
			</view>
			<view class="tit" :class="{'isScroll':isScroll}">
				<view class="t_image">
					<view class="arror_box" @click="$navBack()">
						<image class="arror" src="@/pages/groupbuy/static/home/r_arror_back.png" ></image>
					</view>
					<image class="group_tit" src="@/pages/groupbuy/static/home/group_tit.png" mode="heightFix"></image>
				</view>
			</view>
		</view>
		<view class="list_box">
			<view class="l_tit">
				<view class="search_top">
					<view class="inp_box">
						<input class="uni-input" v-model="body.nickname" placeholder="请输入发起人名称 " />
					</view>
					<view class="search_btn" @click="search">
						<text>搜索</text>
						<image src="@/pages/groupbuy/static/home/search.png" ></image>
					</view>
				</view>
			</view>
			<!-- ---------------购物券------------ -->
			<!-- <view @click="goGroupDetails(1)">
				购物券订单详情
			</view>
			<view @click="goGroupDetails(2)">
				米分订单详情
			</view> -->
			<view class="goods_list">
				<view class="gl_box flex" v-for="item,i in list" @click.stop="joinGroupSumbit(item)">
					<view class="left">
						<image :src="item.pintuan_card_info.img"></image>
					</view>
					<view class="right flex">
						<view class="">
							<view class="g_tit">
								{{item.pintuan_card_info.name}}
							</view>
							<view class="show_num">
								<view class="num">
									{{item.pintuan_card_info.success_num}} 人团
								</view>
								<view class="group_now">
									<image src="@/pages/groupbuy/static/home/group_buying.png"></image>
									<text v-if="item.group_num!=1">共 {{item.group_num}} 个拼团</text>
									<text v-else>还差 {{item.remain_num}} 人拼成</text>
								</view>
							</view>
							<view class="user_group">
								<image :src="item.leader_member_info.avatar" ></image>
								<text class="clamp">{{item.leader_member_info.nickname}}</text>
								<view style="white-space: nowrap;">发起本次拼团</view>
							</view>
							<view class="user_group time" v-if="item.expire_time">
								<view class="tit">距拼团结束：</view>
								<view>
									<countdoen :targetTime="item.expire_time*1000" color="#9A1FE8"
										labelColor="#9A1FE8" :fontSize="12" :fontWeight="800" />
								</view>
							</view>
						</view>

						<view class="list_bottom flex">
							<view class="price">
								<text class="p_logo">￥</text>{{item.pintuan_card_info.price }}
							</view>
							<view class="btn">
								<view class="b_box">
									<image src="@/pages/groupbuy/static/home/join_group.png"></image>
									<text class="none_group">立即参团<text class="right_arror">></text></text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="empty_loading2">
				<image v-if="isloading" src="@/pages/groupbuy/static/loading.gif"></image>
				<view v-if="isempty">———— <text>没有更多了</text> ————</view>
			</view>
		</view>
		<groupVideo />
	</view>

</template>

<script>
	import {
		throttle
	} from 'lodash';
	// import groupVideo from './components/video.vue';
	// import countdoen from './components/countdoen.vue'
	export default {
		components: {
			groupVideo,
			countdoen
		},
		data() {
			return {
				activityTab: 2,
				isScroll: false,
				isTitScroll: false,
				popu: false,
				info: [],
				list: [],
				body: {
					page: 0,
					nickname: ''
				},
				isloading: false,
				isempty: false,
				park_info: {},
				goodsid: '',
				parkId: '',
				groupType: '',
				isRequesting: false, // 请求锁：防止同一时间发多个请求
				currentRequestKey: '' // 当前请求标识：标记“正在等待响应的请求属于哪个Tab/页码”

			}
		},
		onLoad() {
			this.getList();
		},
		onPageScroll(e) {
			this.isScroll = e.scrollTop > 0
			this.isTitScroll = e.scrollTop > 145
		},
		onShow() {
			// this.$refs.bar.initCurrentIndex()
		},
		onReachBottom() {
			if (!this.isempty) this.getList();
		},
		methods: {
			goGroupDetails(type){
				this.$navTo(`/pages/groupbuy/orderDetails?type=${type}`)
			},
			// 立即参团
			joinGroupSumbit(item) {
				uni.removeStorageSync('mid')
				this.$navTo(`/pages/groupbuy/createOrder?multi=1&type=2&id=${item.goodsid}&pintuan_list_id=${item.id}`)
			},
			// 绑定手机号
			getUserProfile(e) {
				// return;
				let that = this;
				// #ifdef MP-WEIXIN
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						let obj = e.detail;
						obj.code1 = loginRes.code;
						that.$axios('bindmobile/bmobile', "POST", 'member', obj).then(res => {
							if (res.data.code == 200) {
								that.$refs.popupMobile.close();
							}
						})
					},
					fail() {
						that.$api.msg('绑定失败，请重试！')
					}
				})
				// #endif
			},
			search: throttle(function() {
				this.list = []
				this.body.page = 0
				this.getList()
			}, 1000, {
				leading: true,
				trailing: false
			}),
			getList() {
				this.body.page++;
				this.isloading = true;
				this.$axios('Group/groupSearch', 'POST', 'pintuan', {
					...this.body
				}).then(res => {
					this.isloading = false;
					if (res.data.code === 200) {
						const newList = res.data.data.list || [];
						this.list = [...this.list, ...newList];
						this.isempty = newList.length < 20;
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fdf8ff;
	}

	:v-deep.empty_loading2 {
		margin-bottom: 50rpx;
	}

	.nobind {
		position: relative;

		.e_close {
			width: 30rpx;
			height: 30rpx;
			position: absolute;
			right: 20rpx;
			top: 20rpx;
		}
	}

	.flex {
		display: flex;
		justify-content: space-between;
	}

	.list_box {
		position: relative;
		top: -10px;
		border-radius: 30rpx 30rpx 0 0;
		background-color: #fdf8ff;
		z-index: 8;
		overflow: hidden;
		padding-bottom: 60rpx;

		.goods_list {
			padding: 20rpx;

			// background-color: pink;
			.right {
				flex-direction: column;
				width: 400rpx;

				.list_bottom {
					align-items: center;
					background: #faf4fd;
					border-radius: 16rpx;
					padding: 0 10rpx;
					overflow: hidden;

					.price {
						color: #9A1FE8;
						font-size: 32rpx;
						font-weight: bold;

						.p_logo {
							font-size: 20rpx;
							font-weight: normal;
						}
					}

					.btn {

						.b_box {
							width: 206rpx;
							height: 60rpx;
							position: relative;
							// background: pink;

							image {
								position: absolute;
								width: 100%;
								height: 100%;
							}

							.none_group {
								position: absolute;
								width: 180rpx;
								height: 60rpx;
								right: 0;
								top: 0;
								text-align: center;
								line-height: 60rpx;
								font-weight: bold;
								font-size: 24rpx;
								color: #FFFFFF;
							}

							.right_arror {
								width: 14rpx;
								margin-left: 8rpx;
								position: static;
							}

						}
					}

					.btn2 {
						width: 176rpx;
						height: 60rpx;
						line-height: 60rpx;
						text-align: center;
						background: #9A1FE8;
						border-radius: 144rpx;
						color: #FFFFFF;
						font-weight: bold;
					}
				}

				.show_num {
					color: #9A1FE8;
					margin-top: 15rpx;
					display: flex;
					align-items: center;

					.num {
						font-size: 20rpx;
						font-weight: bold;
						color: #FFFFFF;
						background: linear-gradient(90deg, #B62BF0 0%, #8813E2 100%);
						width: 102rpx;
						height: 36rpx;
						border-radius: 8rpx;
						margin-right: 10rpx;
						text-align: center;
						line-height: 36rpx;
						padding: 0 5rpx;
					}

					.group_now {
						display: flex;
						align-items: center;

						image {
							width: 120rpx;
							height: 36rpx;
							z-index: 99;
						}

						text {
							background-color: #f5e9fd;
							font-size: 20rpx;
							height: 36rpx;
							line-height: 36rpx;
							padding: 0 20rpx;
							border-radius: 8rpx;
							margin-left: -20rpx;
						}
					}
				}

				.user_group {
					display: flex;
					align-items: center;
					margin-top: 10rpx;

					image {
						width: 24rpx;
						height: 24rpx;
						margin-right: 10rpx;
						border-radius: 50%;
						flex-shrink: 0;
					}

					text {
						font-size: 24rpx;
						font-weight: bold;
						color: #9A1FE8;
						margin-right: 10rpx;
					}

					view {
						font-size: 24rpx;
						color: #5B5B5B;
					}
				}

				.time {
					justify-content: space-between;
					.tit{
						white-space: nowrap;
					}

					.time {
						font-size: 24rpx;
					}
				}

				.g_tit {
					width: 100%;
					color: #13001E;
					font-size: 28rpx;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					/* 限制显示的行数 */
					-webkit-box-orient: vertical;
					overflow: hidden;
				}
			}

			.gl_box {
				border-radius: 24rpx;
				background: #FFFFFF;
				padding: 20rpx;
				width: 100%;
				height: 284rpx;
				margin-bottom: 20rpx;

				.left {
					image {
						width: 244rpx;
						height: 244rpx;
						border-radius: 8rpx;
						box-shadow: 0 0 4rpx 4rpx rgba(153, 153, 153, 0.15);
					}
				}
			}
		}

		.time_box {
			width: 100%;
			padding: 0 20rpx;
			// height: 60rpx;
			align-items: center;

			.tb_left {
				text {
					font-size: 24rpx;
				}

				.tit_time {
					color: #13001E;
					font-weight: normal;
				}

				.time {
					color: #9A1FE8;
					font-weight: bold;
				}
			}
		}

		.l_tit {
			width: 100%;
			padding: 24rpx 30rpx;
			background: #FDF8FF;

			.search_top {
				display: flex;
				justify-content: space-between;

				.search_btn {
					width: 160rpx;
					height: 64rpx;
					border-radius: 16rpx;
					background: #9A1FE8;
					display: flex;
					align-items: center;
					justify-content: center;

					text {
						color: #FFFFFF;
						font-size: 28rpx;
						font-weight: bold;
					}

					image {
						width: 36rpx;
						height: 36rpx;
						margin-left: 8rpx;
					}
				}

				.inp_box {
					width: 520rpx;
					height: 64rpx;
					border-radius: 16rpx;
					background: #FFFFFF;
					border: 2rpx solid #CCCACD;
					padding: 0 10rpx;

					.uni-input {
						width: 520rpx;
						height: 64rpx;
						font-size: 28rpx;
					}
				}
			}
		}
	}

	.top {
		.top_bg {
			height: 450rpx;
			width: 100%;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.tit {
			position: absolute;
			// height: 90px;
			top: 0;
			left: 0;
			width: 100%;
			display: flex;
			flex-direction: column;
			justify-content: flex-end;
			padding: 0 30rpx;
			padding-top: calc(var(--status-bar-height) + 50rpx);
			padding-bottom: 0;

			.t_image {
				display: flex;
				align-items: center;

			}

			.group_tit {
				height: 60rpx;
			}

			.arror_box {
				width: 40rpx;
				height: 34rpx;

				.arror {
					width: 18rpx;
					height: 34rpx;
				}
			}
		}
	}

	.tit.isScroll {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		/* 确保宽度满屏 */
		height: 90px;
		background-color: yellow;
		z-index: 9999;
		/* 提高层级，避免被遮挡 */
		// padding: 0 30rpx;
		padding-bottom: 10px;
		/* 调整内边距 */
		box-sizing: border-box;
		/* 确保宽度包含内边距 */
		background: linear-gradient(180deg, #9A1FE8 0%, #FFFFFF 100%);
		border-bottom: 2px solid #CCCACD;
	}

	.isTitScroll {
		position: fixed;
		top: 110px;
		z-index: 9999;
		/* 提高层级，避免被遮挡 */
	}
</style>